package com.futureCloudMOM.common.utils.core;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.futureCloudMOM.common.utils.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Mybatis-Plus 提供的公共字段自动填充
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    //新增插入
    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("sysCreateTime",new Date());
        metaObject.setValue("sysUpdateTime",new Date());
        metaObject.setValue("sysCreateUser", SecurityUtils.getUserId());
        metaObject.setValue("sysUpdateUser", SecurityUtils.getUserId());
    }

    //修改插入
    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("sysUpdateTime",new Date());
        metaObject.setValue("sysUpdateUser", SecurityUtils.getUserId());
    }
}
